package com.yc.ui.admin;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.layout.FillLayout;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import com.yc.Idao.GoodsIDao;
import com.yc.dao.GoodsDao;
import com.yc.ui.Order;
import com.yc.utils.SWTUtil;

import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class Users extends Composite {
	private Table table;
	
	GoodsIDao dao = new GoodsDao();
	private Text text_name;
	private Text text_tel;
	private Text text_cardid;
	private Text text_mail;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public Users(Composite parent, int style) {
		super(parent, style);
		setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Composite composite = new Composite(this, SWT.NONE);
		composite.setLayout(null);
		composite.setBackgroundImage( SWTResourceManager.getImage(Order.class, "/com/yc/images/客房预约1.PNG") );
		SWTUtil.imagetSize(composite);				
		table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION);
		table.setBounds(0, 145, 1059, 527);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn.setWidth(89);
		tblclmnNewColumn.setText("编号");
		
		TableColumn tblclmnNewColumn_2 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_2.setWidth(97);
		tblclmnNewColumn_2.setText("姓名");
		
		TableColumn tableColumn_3 = new TableColumn(table, SWT.NONE);
		tableColumn_3.setWidth(61);
		tableColumn_3.setText(" 性别");
		
		TableColumn tblclmnNewColumn_3 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_3.setWidth(146);
		tblclmnNewColumn_3.setText("用户密码");
		
		TableColumn tblclmnNewColumn_4 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_4.setWidth(201);
		tblclmnNewColumn_4.setText("身份证");
		
		TableColumn tableColumn = new TableColumn(table, SWT.NONE);
		tableColumn.setWidth(179);
		tableColumn.setText("手机号");
		
		TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
		tableColumn_1.setWidth(185);
		tableColumn_1.setText("邮箱");
		
		TableColumn tableColumn_2 = new TableColumn(table, SWT.NONE);
		tableColumn_2.setWidth(99);
		tableColumn_2.setText("余额");
		
	
		
		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setBounds(317, 31, 76, 20);
		lblNewLabel.setText("姓名：");
		
		text_name = new Text(composite, SWT.BORDER);
		text_name.setBounds(411, 28, 155, 26);
		
		Label lblNewLabel_1 = new Label(composite, SWT.NONE);
		lblNewLabel_1.setBounds(317, 87, 76, 20);
		lblNewLabel_1.setText("身份证：");
		
		text_cardid = new Text(composite, SWT.BORDER);
		text_cardid.setBounds(411, 84, 155, 26);
		
		Label lblNewLabel_2 = new Label(composite, SWT.NONE);
		lblNewLabel_2.setBounds(617, 31, 76, 20);
		lblNewLabel_2.setText("手机号：");
		
		text_tel = new Text(composite, SWT.BORDER);
		text_tel.setBounds(699, 28, 147, 26);
		
		Label lblNewLabel_3 = new Label(composite, SWT.NONE);
		lblNewLabel_3.setBounds(618, 87, 64, 20);
		lblNewLabel_3.setText("邮箱：");
		
		text_mail = new Text(composite, SWT.BORDER);
		text_mail.setBounds(699, 84, 147, 26);
		
		Button btnNewButton = new Button(composite, SWT.NONE);
		
		btnNewButton.setBounds(894, 26, 98, 30);
		btnNewButton.setText("查询");
		
		Label lblNewLabel_4 = new Label(composite, SWT.NONE);
		lblNewLabel_4.setBounds(23, 31, 76, 20);
		lblNewLabel_4.setText("查询方式");
		
		Combo combo_choice = new Combo(composite, SWT.NONE);
		combo_choice.setItems(new String[] {"按全部查询", "按姓名查询", "按身份证查询", "按手机号查询", "按邮箱查询"});
		combo_choice.setBounds(121, 31, 164, 28);
		combo_choice.select(0);
		
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String info = combo_choice.getText();//下拉框的选项
				
				Map<String,Object> map = null;
				if("按全部查询".equals(info)){
					//在表格中添加所查记录
					showInfo(map);
				}
				if("按姓名查询".equals(info)){
					map = new HashMap<String,Object>();
					map.put("c_name", text_name.getText().toString());
					showInfo(map);
				}
				if("按身份证查询".equals(info)){
					map = new HashMap<String,Object>();
					map.put("c_cardid", text_cardid.getText().toString());
					showInfo(map);
				}
				if("按手机号查询".equals(info)){
					map = new HashMap<String,Object>();
					map.put("c_tel", text_tel.getText().toString());
					showInfo(map);
				}
				if("按邮箱查询".equals(info)){
					map = new HashMap<String,Object>();
					map.put("c_eml", text_mail.getText().toString());
					showInfo(map);
				}
			}
		});
		showInfo(null);
	}
	
	protected void showInfo(Map<String, Object> map) {
		//清除表格
		table.removeAll();
		List<Map<String, Object>> list = dao.findcustomer(map);
		TableItem tableItem = null;
		//判空
		if(null == list || list.isEmpty()) {
			SWTUtil.showMessage(getShell(), "查无会员信息");
			return;
		}
		for(Map<String, Object> m : list) {
			tableItem = new TableItem(table, SWT.NONE);
			tableItem.setText(new String[] {
					m.get("c_id").toString(),
					m.get("c_name").toString(),
					m.get("c_sex").toString(),
					m.get("c_pwd").toString(),
					m.get("c_cardid").toString(),
					m.get("c_tel").toString(),
					m.get("c_eml").toString(),
					m.get("c_money").toString(),
			});
		}
	}
}
